#ifndef HOME_H
#define HOME_H

#include <QWidget>
#include <QInputDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QListWidgetItem>
#include "Code/net/gobang_network.h"
#include "Code/ui/LoadMessage.h"
#include "Code/ui/room_item.h"
#include "create_room.h"

namespace Ui {
class home;
}

class home : public QWidget
{
    Q_OBJECT

private:
    Gobang_Network *gn;
    QRect mypos;
public:
    explicit home(Gobang_Network *gn,QWidget *parent = nullptr);
    ~home();
    void setSize(int x, int y, int w, int h, QRect mypos);

    QString room_text;
    LoadMessage *lm;
private slots:
    void on_toolButton_update_clicked();

    void on_toolButton_createRoom_clicked();

private:
    Ui::home *ui;

    struct {
        QString str;
        int fd;
        int fd_cpy;
    } room_list[40];

    uint16_t item_getID(QListWidgetItem *item);
    QString item_getName(QListWidgetItem *item);
    void list_item_setWidth(int width);
    void join_room(uint16_t fd);
public slots:
    void create_post();
    void create_fail();
    void itemClicked(QListWidgetItem *item);
    void purge_list();
    void list_addItem(uint16_t fd, QString str);

signals:
    void on_create_room();
};


#endif // HOME_H
